#include <stdio.h>
 
int main()
{
	freopen("zz_test\\test1.in", "r", stdin);
	freopen("zz_test\\test1.out", "w", stdout);

    long long m = 0, n = 0;
    scanf("%lld %lld", &m, &n);
    if ( m < n ) {
        long long tmp = m;
        m = n;
        n = tmp;
    }
    long long l = m % n;
    while ( l != 0 ) {
        m = n;
        n = l;
        l = m % n;
    }
    printf("%lld", n);
    return 0;
}
